﻿using ACC.Business.Stn;
using ACC.Data.ACCLog;
using ACC.Data.Comm;
using ACC.Data.Line;
using ACC.Device;
using System;
using System.Collections.Generic;
using System.Linq;
using ACC.Data.Entities.Mes;
using ACC.LineDevice.KukaPack;

namespace Script
{
    /// <summary>
    /// 电芯转运
    /// OP L1M01060, STATION L1M11061, L1M21061
    /// 在本站自动查询到前站已经unload OK的6个条码（按时间先后顺序），获得一个出料信号后，托盘转运，分别对6个条码自动unload
    /// 物理工序分流，在程序中前站精确到工站，本站前站为'L1M11051' (OP L1M01050 已无)
    /// </summary>
    public class L1M01060 : StnProcessPL02_DX
    {
        public L1M01060(StnRunningData data)
            : base(data)
        {
        }

        protected override ACCDevice CreateDevice()
        {
            ACCDevice dev = base.CreateDevice();
            if (kukaSiemensDev != null)
            {
                switch (_data.StnCfg.Name)
                {
                    case "L1M11061":
                        {
                            kukaSiemensDev.DB190_Offset = 2000;
                        }
                        break;
                    case "L1M21061":
                        {
                            kukaSiemensDev.DB190_Offset = 5000;
                        }
                        break;
                }

                kukaSiemensDev.DB190 = 800;
                kukaSiemensDev.DB192 = 80;
                kukaSiemensDev.DB192_PLC_Offset =  (ushort)(kukaSiemensDev.DB190_Offset + 258);
                kukaSiemensDev.DB193 = 800;
                kukaSiemensDev.DB193_PLC_Offset = (ushort)(kukaSiemensDev.DB190_Offset + 66);
                kukaSiemensDev.DB193_ACC_Offset = (ushort)(kukaSiemensDev.DB190_Offset + 68);
                kukaSiemensDev.DB194 = 800;
                kukaSiemensDev.DB194_PLC_Offset = (ushort)(kukaSiemensDev.DB190_Offset + 66);
                kukaSiemensDev.DB194_PLC_Data_Offset = kukaSiemensDev.DB190_Offset + 270;
                kukaSiemensDev.Material_COMM_Offset = 260; //260, 5260 上下料信号位偏移量

                kukaSiemensDev.BarcodeLength = 30;
                kukaSiemensDev.LoadBarcodeCount = 6;
                kukaSiemensDev.UnloadBarcodeCount = 6;
            }

            return dev;

        }

        protected override void CreateBusinessLogic()
        {
            base.CreateBusinessLogic();

            (_loadProcess as LoadProcess_DX).R = 1;
            (_unloadProcess as UnloadProcess_DX).R = 1;
            (_unloadProcess as UnloadProcess_DX).OneAsNG = true;
        }
    }
}
